const express = require("express");

const app = express();

/* 静态资源使用 */
app.use(express.static(__dirname + "/static")).use((request,response,next)=>{
	console.log('有人请求服务器1了');
	console.log('请求来自于',request.get('Host'));
	console.log('请求的地址',request.url);
	next()
});

/* 指定路径数据返回 */
app.get("/students", (req, res) => {
  console.log("req", req);
  console.log("res", res);
  res.send({
    name: "tom",
    age: 18,
  });
});

app.get("/", (req, res) => {
  console.log("req", req);
  console.log("res", res);
  res.send({
    name: "123",
    age: 11118,
  });
});

/* 创建端口监听 */
app.listen(8888, (err) => {
  if (!err) {
    console.log("服务器启动成功! 地址为：http://localhost:8888/students");
  }
});
